use std::string::String;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use plugin_manager::PluginError;

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ITrusteeConfig {
    pub plugin_type: String,
    pub ta_uuid: String,
}

impl ITrusteeConfig {
    pub fn from_json(plugin_type: String, config_json: &str) -> Result<Self, PluginError> {
        let config: Value = serde_json::from_str(config_json).map_err(|e| PluginError::InternalError(format!("Failed to parse plugin configuration as JSON: {}", e)))?;
        let ta_uuid = config.get("uuid").ok_or_else(|| PluginError::InternalError("missing uuid in config".to_string()))?
            .as_str().ok_or_else(||PluginError::InputError("missing uuid in config".to_string()))?.to_string();
        Ok(Self {
            plugin_type,
            ta_uuid: ta_uuid,
        })
    }
}